package com.example.zhangwei.ui.tabactivityfragment;


import com.example.zhangwei.R;
import com.example.zhangwei.ui.tabactivityfragment.activity.OneActivityFranment;
import com.example.zhangwei.ui.tabactivityfragment.activity.TwoActivityFranment;

import android.annotation.SuppressLint;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

@SuppressWarnings("deprecation")
public class MyTabActivity extends TabActivity{
	
	@SuppressLint("NewApi")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.my_tab_activity_fragment_layout);
		
		TabHost tabHost = getTabHost();
		
		// 页面1
        tabHost.addTab(tabHost.newTabSpec("页面1").setIndicator(
                createIndicator("页面1", R.drawable.menu_first_icon_gray)).setContent(
                new Intent(this, OneActivityFranment.class)));

        // 页面2
        tabHost.addTab(tabHost.newTabSpec("页面2").setIndicator(
                createIndicator("页面2", R.drawable.menu_second_icon_gray)).setContent(
                new Intent(this, TwoActivityFranment.class)));

	}
	
	/** 创建tab布局 */
    private View createIndicator(String mLabel, int mIcon)
    {
        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View tabIndicator = inflater.inflate(R.layout.bottom_bar_button, null);

        final TextView tv = (TextView) tabIndicator.findViewById(R.id.bottom_bar_button_text);
        tv.setText(mLabel);

        final ImageView imageView = (ImageView) tabIndicator.findViewById(R.id.bottom_bar_button_image);
        imageView.setImageResource(mIcon);

        return tabIndicator;
    }

}
